﻿package com.lbynet.ui
{
	import flash.utils.Timer;
	import flash.events.*;
	
	/**
	 * ...
	 * @author DefaultUser (Tools -> Custom Arguments...)
	 */
	public class CountdownTimer 
	{
		
		private var _timer:Timer;
		private var timerTick:Function;
		private var finishFun:Function;
		
		public function CountdownTimer() 
		{
			
		}
		
		
		public function getTimer():Timer {
			
			return _timer;
		}
		
		public function setTimer(delay:int = 1000, repeatCount:int = 30):void {
			
			if (_timer != null && _timer.running) this._timer.stop();
			
			_timer = new Timer(delay, repeatCount);
			
		}
		public function startTrun(timerTick:Function = null , finishFun:Function = null){
		    
			this.timerTick = timerTick;
			this.finishFun = finishFun;
			
			if(this.timerTick != null) _timer.addEventListener(TimerEvent.TIMER, this.timerTick );
			if(this.finishFun != null) _timer.addEventListener(TimerEvent.TIMER_COMPLETE, this.finishFun );
			_timer.start();
		}
		
		
		public function stopClock():void {
			
			if (this._timer != null && this._timer.running ) this._timer.stop();
		}
		
		
	}
	
}